package com.zhoushihao.class0811;

import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

public class Guess {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] str = {"extends", "abstract", "hello", "index"};
        Random random = new Random();
        int index = random.nextInt(str.length);
        String real = str[index];
        char[] guess = new char[real.length()];
        Arrays.fill(guess, '-');
        System.out.println(String.valueOf(guess));
        int count = 5;
        while (count > 0) {
            if (real.equals(String.valueOf(guess))) {
                break;
            }
            String str1 = sc.next();
            if (real.contains(str1)) {
                for (int j = 0; j < real.length(); j++) {
                    if (real.charAt(j) == str1.charAt(0)) {
                        guess[j] = str1.charAt(0);
                    }
                }
                System.out.println(String.valueOf(guess));
            } else {
                count--;
                System.out.println("你还剩" + count + "次机会");
            }
        }
        if (real.equals(String.valueOf(guess))) {
            System.out.println("恭喜你猜对了");
        } else {
            System.out.println("很抱歉你猜错了");
        }
        System.out.println("真实答案是:" + real);
    }
}
